package top.tagao.yygh.user.controller.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tagao.yygh.common.result.Result;
import top.tagao.yygh.common.utils.AuthContextHolder;
import top.tagao.yygh.model.user.UserInfo;
import top.tagao.yygh.user.service.UserInfoService;
import top.tagao.yygh.vo.user.LoginVo;
import top.tagao.yygh.vo.user.UserAuthVo;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author fu-xiao-liu
 * @Date 2022/3/8 17:50
 */
@Api(tags = "用户登录管理")
@RestController
@RequestMapping("/api/user")
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "用户认证接口")
    @PostMapping("auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request) {
        //传递两个参数，第一个参数用户id，第二个参数认证数据vo对象
        userInfoService.userAuth(AuthContextHolder.getUserID(request),userAuthVo);
        return Result.ok();

    }



    @ApiOperation(value = "获取用户信息接口")
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){
        Long userID = AuthContextHolder.getUserID(request);
        UserInfo userInfo = userInfoService.getById(userID);
        return Result.ok(userInfo);
    }



    @ApiOperation(value = "手机号登录")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo) {
        Map<String,Object> info = userInfoService.loginUser(loginVo);
        return Result.ok(info);
    }
}
